package com.xsd.awen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xsd.awen.domain.entity.Task;
import com.xsd.awen.domain.entity.UserTask;
import com.xsd.awen.domain.po.UserTaskPagePo;
import com.xsd.awen.domain.vo.UserTaskVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserTaskMapper extends BaseMapper<UserTask> {

    @Select("<script> " +
            " select u.*,p.cname projectName," +
            " ( select group_concat(user.name) from t_tk_user user where user.id in ( select user_id from t_tk_user_task ut where ut.task_id = u.id )   ) names " +
            " from t_tk_task u" +
            " inner join t_tk_project p on u.project_id = p.id " +
            " where 1=1 " +
            "<if test=\"task.name != null and task.name != ''\"> and u.name like CONCAT('%', #{task.name}, '%')</if>" +
            "<if test=\"task.appId != null and task.appId != ''\"> and u.app_id = #{task.appId}</if>" +
            "<if test=\"task.gs != null\"> and u.gs = #{task.gs}</if>" +
            "<if test=\"task.projectId != null and task.projectId != ''\"> and u.project_id = #{task.projectId}</if>" +
            " order by u.create_time desc " +
            "</script>")
    List<UserTaskPagePo> page(UserTaskVo userTaskVo);

    @Select(" select * from t_tk_user_task where task_id = #{id} ")
    List<UserTask> get(Task task);

    @Delete("delete from t_tk_user_task where task_id = #{taskId}")
    void deleteByTaskId(UserTask userTask);

}